package Base.线程池.Executor接口实现线程池管理;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author 陈鹏
 */
public class Runnable_Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Mythread5 mythread5=new Mythread5();
        Thread thread1=new Thread(mythread5,"thread1");
        Thread thread2=new Thread(mythread5,"thread2");
        ExecutorService executor= Executors.newCachedThreadPool();
        Future result1 =executor.submit(thread1);
        Future result2 =executor.submit(thread2);
        executor.shutdown();
        System.out.println("thread1-----"+result1);
        System.out.println("thread2-----"+result2);
        System.out.println("thread1-----"+result1.get());
        System.out.println("thread2-----"+result2.get());



    }
}

class Mythread5 implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"正在运行！！");
    }
}
